//namespace unix_API {
//// Currently the check is performed for apple targets only.
//void test(const char* path) {
//    int fd = open(path, O_CREAT);
//    // warn: call to 'open' requires a third argument when the
//    // 'O_CREAT' flag is set
//}
//
//void f();
//
//void test() {
//    pthread_once_t pred = { 0x30B1BCBA, {0} };
//    pthread_once(&pred, f);
//    // warn: call to 'pthread_once' uses the local variable
//}
//
//void test() {
//    void* p = malloc(0); // warn: allocation size of 0 bytes
//}
//
//void test() {
//    void* p = calloc(0, 42); // warn: allocation size of 0 bytes
//}
//
//void test() {
//    void* p = malloc(1);
//    p = realloc(p, 0); // warn: allocation size of 0 bytes
//}
//
//void test() {
//    void* p = alloca(0); // warn: allocation size of 0 bytes
//}
//
//void test() {
//    void* p = valloc(0); // warn: allocation size of 0 bytes
//}
//
//}

#ifdef _WIN32
#include <malloc.h>  // For malloc, calloc, realloc, alloca
#include <io.h>      // For open
#include <fcntl.h>   // For O_CREAT
#include <Windows.h> // For Windows-specific types and functions like pthread_once
#include <cstdlib>
inline int open(const char* path, int oflag, int mode = 0) {
    return _open(path, oflag, mode);
}

// Dummy pthread_once function for Windows
typedef struct { volatile long once_flag; } pthread_once_t;
#define PTHREAD_ONCE_INIT {0}
inline int pthread_once(pthread_once_t* once_control, void (*init_routine)(void)) {
    static long initialized = 0;
    if (InterlockedCompareExchange(&initialized, 1, 0) == 0) {
        init_routine();
    }
    return 0;
}

#else
#include <fcntl.h>    // For open, O_CREAT
#include <pthread.h>  // For pthread_once
#include <unistd.h>   // For malloc, realloc, alloca, valloc
#include <stdlib.h>   // For calloc, malloc
#include <stdio.h>    // For printf (in case of errors)
#endif

namespace unix_API {

    void test(const char* path) {
        int fd = open(path, O_CREAT, 0644);
        // warn: call to 'open' requires a third argument when the
        // 'O_CREAT' flag is set
    }

    void f() {
        // Some function implementation
    }

    void test() {
        pthread_once_t pred = PTHREAD_ONCE_INIT;
        pthread_once(&pred, f);
        // warn: call to 'pthread_once' uses the local variable
    }

    void test() {
        void* p = malloc(0); // warn: allocation size of 0 bytes
    }

    void test() {
        void* p = calloc(0, 42); // warn: allocation size of 0 bytes
    }

    void test() {
        void* p = malloc(1);
        p = realloc(p, 0); // warn: allocation size of 0 bytes
    }

    void test() {
        void* p = alloca(0); // warn: allocation size of 0 bytes
    }

    void test() {
#ifdef _WIN32
#else
        void* p = valloc(0); // warn: allocation size of 0 bytes
#endif
    }

}
